package com.example;

import org.junit.Test;

import java.util.Random;

public class MathTest {

    @Test
    public void test01() {
        System.out.println(Math.abs(-3)); // 绝对值
        System.out.println(Math.sqrt(9)); // 平方根3.0
        System.out.println(Math.ceil(3.6)); // 向上化整,4
        System.out.println(Math.floor(3.6)); // 向下化整,3
        System.out.println(Math.ceil(-3.6)); // -3
        System.out.println(Math.floor(-3.6)); // -4
        int a = 3,b = 4;
        int max = 0;
        if (a > b) {
            max = a;
        } else {
            max = b;
        }
        max = Math.max(a, b); // 取大值
        max = a > b ? a : b;
    }

    @Test
    public void test02() {
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            int x = random.nextInt(100); // 0~99
        }
        for (int i = 0; i < 10; i++) {
            /* 产生10个0~99的随机数 */
            double x = Math.random();
            // 底层为random.nextDouble()
            x = 100 * x;
            double y = Math.floor(x);
            System.out.println(y);
        }
    }
}
